<template>
	<div id="welcome">
		<el-card>
			<el-card class="cadds" v-for="it in uslist">
				<div class="cadd">

					<div class="fl">
						<img src="../../assets/morentouxiang.jpg" />
					</div>
					<div class="fr">
						<div>登录名称：{{it.LoginName}}</div>
						<el-button type="primary" @click="dialogPasswordFormVisible=true">修改密码</el-button>
					</div>
				</div>
				<div class="ca-time">登录名称：{{it.LastLoginTime}}</div>
			</el-card>
			<div style="margin-top: 20px;">
				<el-button v-show="istrue" type="primary" round @click="up">上班打卡</el-button>
				<el-button v-show="istrue" type="warning" round @click="down">下班打卡</el-button>
			</div>
			<el-dialog title="修改密码" :visible.sync="dialogPasswordFormVisible">
				<el-form :model="Passwordform" ref="PasswordformRef" :rules="rules">
					<el-form-item label="旧密码" prop="password">
						<el-input type="password" v-model="Passwordform.password" auto-complete="off"></el-input>
					</el-form-item>
					<el-form-item label="新密码" prop="newpassword">
						<el-input type="password" v-model="Passwordform.newpassword" auto-complete="off"></el-input>
					</el-form-item>
				</el-form>
				<div slot="footer" class="dialog-footer">
					<el-button @click="dialogPasswordFormVisible = false">取 消</el-button>
					<el-button type="primary" @click="submitPass">确 定</el-button>
				</div>
			</el-dialog>
		</el-card>
	</div>
</template>

<script>
	export default {
		data() {
			return {
				vedioCanPlay: false,
				fixStyle: '',
				show: false,
				//是否是咨询师
				istrue: false,
				uslist: [],
				dialogPasswordFormVisible: false,
				Passwordform: {},
				rules: {
					password: [{
							required: true,
							message: '请输入旧密码',
							trigger: 'blur'
						},
						{
							min: 6,
							max: 8,
							message: '长度在 3~10 个字符',
							trigger: 'blur'
						}
					],
					newpassword: [{
							required: true,
							message: '请输入新密码',
							trigger: 'blur'
						},
						{
							min: 6,
							max: 8,
							message: '密码的长度在3~10个字符之间',
							trigger: 'blur'
						}
					],
				}
			}
		},
		created() {
			this.getUsList();
		},
		mounted() {
			this.getistrue();
		},
		methods: {
			getistrue() {
				var zixun = JSON.parse(localStorage.getItem("RoleName"));
				console.log(zixun);
				for (var i = 0; i < zixun.length; i++) {
					if (zixun[i] == "咨询师") {
						this.istrue = true
					}
				}
				console.log(this.istrue);

			},
			canplay() {
				this.vedioCanPlay = true
			},
			up() {
				let _this=this;
				this.$axios.get('/api/api/Check/up', {
					params: {
						UserId: parseInt(sessionStorage.getItem("Id")),
						time: this.gettime()
					}
				}).then(function(res){
					if (res.data.code == 0) {
						_this.GetCheckList();
						_this.$message.success("签退成功！");
					} else if (res.data.code == -1) {
						_this.$message.error(res.data.msg);
					} else if (res.data.code == -2) {
						_this.$message.error(res.data.msg);
					} else if (res.data.code == -3) {
						_this.$message.error(res.data.msg);
					} else if (res.data.code == 1) {
						_this.$message.success(res.data.msg);
					}
				}).catch(function(err){
					_this.$message.error(err);
				})
				
			},
			async down() {
				const delresult = await this.$confirm('是否签退, 是否继续?', '签退提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).catch(err => err)
				if (delresult !== 'confirm') {
					return this.$message.info('已经取消签退！')
				}
				let _this = this;
				_this.$axios.post('/api/api/Check/resetuser', {
					UserID: parseInt(sessionStorage.getItem("Id")),
					time: this.gettime()
				}).then(function(res) {
					if (res.data.code == 0) {
						_this.GetCheckList();
						_this.$message.success("签退成功！");
					} else if (res.data.code == -1) {
						_this.$message.error(res.data.msg);
					} else if (res.data.code == -2) {
						_this.$message.error(res.data.msg);
					} else if (res.data.code == -3) {
						_this.$message.error(res.data.msg);
					} else if (res.data.code == -4) {
						_this.$message.error(res.data.msg);
					} else if (res.data.code == -5) {
						_this.$message.error(res.data.msg);
					}
				}).catch(function(err) {
					_this.$message.error("重置失败！");
				})
			},
			gettime() {
				var nowDate = new Date();
				let date = {
					year: nowDate.getFullYear(),
					month: nowDate.getMonth() + 1,
					day: nowDate.getDay(),
					h: nowDate.getHours(),
					s: nowDate.getMinutes(),
					ss: nowDate.getSeconds()
				};
				let systemDate = date.year + "年" + date.month + "月" + date.h + "时" + date.s + "分" + date.ss + "秒";
				return systemDate
			},
			//修改密码
			submitPass() {
				let _this = this;
				this.$axios.post('/api/api/Home/UpdatePass', {
					password: this.Passwordform.password,
					newpassword: this.Passwordform.newpassword,
					Id: parseInt(window.sessionStorage.getItem("token"))
				}).then(function(res) {
					console.log(res.data.code);
					if (res.data.code == 0) {
						_this.dialogPasswordFormVisible = false;
						this.$message.success(res.data.msg);
						_this.$router.push("/login");
					} else if (res.data.code == -1) {
						_this.$message.error(res.data.msg);
					} else {
						_this.$message.error(res.data.msg);
					}
				}).catch(function(err) {
					this.$message.success(err.msg)
				})
			},
			//获取用户
			getUsList() {
				let s = window.sessionStorage.getItem('token');
				console.log(s);
				let _this = this;
				this.$axios.post('/api/api/Home/GetUsList', {
					Id: parseInt(s)
				}).then(function(res) {
					console.log(res.data.data);
					if (res.status == 200) {
						// console.log(res);
						_this.uslist = res.data.data
					}
				}).catch(function(res) {
					console.log(res);
				})
			}
		}
	}
</script>


<style>
	.cadds {
		width: 480px;
	}

	.cadd {
		margin: 0 auto;
		overflow: hidden;
	}

	.fl {
		float: left;
		margin-bottom: 20px;
	}

	.fl img {
		border-radius: 50%;
		width: 100px;
		height: 100px;
	}

	.fr {
		float: right;
	}

	.fr div {
		font-size: 24px;
	}

	.fr button {
		margin-top: 20px;
	}

	.ca-time {
		font-size: 24px;
	}
</style>
